package com.fxsh168.server.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.fxsh168.server.R;

import java.util.List;


/**
 * 自定义消息adapter类
 */
public class MyYaoAdapter extends BaseAdapter {
    private List<String> listData;//数据源
    private Context context;//上下文

    public MyYaoAdapter(List<String> strings, Context context) {
        this.listData = strings;
        this.context = context;
    }

    @Override
    public int getCount() {
        return listData == null ? 0 : listData.size();
    }

    @Override
    public Object getItem(int position) {
        return listData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.my_yao_item, null);
            viewHolder = new ViewHolder();
            viewHolder.teYaoPhone = (TextView) convertView.findViewById(R.id.teYaoPhone);//复用消息

            convertView.setTag(viewHolder);//给convertView设置标签
        } else {
            viewHolder = (ViewHolder) convertView.getTag();//通过标签获得viewHolder
        }
        //获得数据
        viewHolder.teYaoPhone.setText(listData.get(position));
        return convertView;
    }


    //创建ViewHolder内部类
    class ViewHolder {
        TextView teYaoPhone;
    }
}
